//
//  SHSearDetailController.m
//  UI_CarHome
//
//  Created by dllo on 15/11/7.
//  Copyright (c) 2015年 沈浩. All rights reserved.
//

#import "SHSearDetailController.h"
#import "SHHandle.h"
#import "SHSeaDetailCell.h"
#import "SHDetailViewController.h"
@interface SHSearDetailController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *relatedseriesmodelArr;
@end

@implementation SHSearDetailController
- (void)dealloc
{
    [_tableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.tableView.backgroundColor = BACKGROUNDCOLOR;
    self.tableView.separatorStyle = SEPARATORSTYLE;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isNight:) name:@"isNight" object:nil];
    [self createTableView];
    [self createData];
}
- (void)isNight:(NSNotification *)nsnotification {
    [self.tableView reloadData];
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.tableView.backgroundColor = BACKGROUNDCOLOR;
    self.tableView.separatorStyle = SEPARATORSTYLE;
}

- (void)createData {
    
    [SHNetWorkingTool getNetWorking:self.webStr block:^(id result) {
        self.relatedseriesmodelArr = [NSMutableArray array];
        self.relatedseriesmodelArr = result[@"result"][@"relatedseriesmodel"];
        [self.tableView reloadData];
    }];
}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 120;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"reuse";
    SHSeaDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[SHSeaDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];
    }
    cell.nameLabel.text = self.relatedseriesmodelArr[indexPath.row][@"name"];
    cell.nameLabel.textColor = TEXTCOLOR;
    [cell.imgImageView sd_setImageWithURL:[NSURL URLWithString:self.relatedseriesmodelArr[indexPath.row][@"img"]]];
    cell.pricebetweenLabe.text = self.relatedseriesmodelArr[indexPath.row][@"lowprice"];
    cell.levelnameLabel.text = self.relatedseriesmodelArr[indexPath.row][@"levelname"];
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.relatedseriesmodelArr.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SHDetailViewController *detail = [[SHDetailViewController alloc] init];
    [self.navigationController pushViewController:detail animated:YES];
    [detail release];
    // http://comm.app.api.autohome.com.cn/static/sharejump.html?p=1&pm=1&go=1&cont=5&ourl=http://m.autohome.com.cn/18/
    NSString *str = [NSString stringWithFormat:@"http://comm.app.api.autohome.com.cn/static/sharejump.html?p=1&pm=1&go=1&cont=5&ourl=http://m.autohome.com.cn/%@/", self.relatedseriesmodelArr[indexPath.row][@"id"]];
    detail.webStr = str;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
